<?php


include_once("config/pay_config.php");
include_once('../../config.php');
/*
 * ��ȡ�?���
 * */
$order_id = (string) $_POST['p2_Order'];//date("YmdHis"); //��Ķ���Id�ţ�������Լ���֤�����ŵ�Ψһ�ԣ���Ѷ�������Ƹ�ֵ��Ψһ��
$payType = 'bank';//$_POST['payType'];  //��ֵ��ʽ��bankΪ����cardΪ����֧��
$account = '';//$_POST['account'];  //��ֵ���˺�
$amount = $_POST['p3_Amt'];   //��ֵ�Ľ��
$pa_MP						= $_POST['pa_MP'];//username

///
$time = date("Y-m-d H:i:s",time()+28800-date("Z",time()));

$conn = mysql_connect($dbhost,$conf['db']['user'],$conf['db']['password']);
if (!$conn)
  {
  die('Could not connect: ' . mysql_error());
  }
mysql_select_db($dbname,$conn);

$pa_MP = mysql_escape_string($pa_MP);

$info = "INSERT INTO ssc_order(order_number, username, recharge_amount, state, time)
VALUES('".$order_id."', '".$pa_MP."', '".$amount."', '0', '".$time."')";

mysql_query($info);

mysql_close($conn);
///
//����֧��
if ('bank' == $payType) {
    //$bankType = $_POST['bankType'];   //��������
    $bankType					= GetBankCode($_REQUEST['rbPayMType']);


    /*
     * �ύ���
     * */
    include_once("eka/class.bankpay.php");
    $bankpay = new bankpay();
    $bankpay->parter = $eka_merchant_id;  //�̼�Id
    $bankpay->key = $eka_merchant_key; //�̼���Կ
    $bankpay->type = $bankType;   //�̼���Կ
    $bankpay->value = $amount;    //�ύ���
    $bankpay->orderid = $order_id;   //����Id��
    $bankpay->callbackurl = $eka_callback_url; //����url��ַ
    $bankpay->hrefbackurl = $eka_bank_hrefbackurl; //����url��ַ
    //����
    $bankpay->send();
}
//����֧��
else if ('card' == $payType) {
    $cardType = $_POST['cardType'];   //������
    $card_number = $_POST['card_number'];  //����
    $card_password = $_POST['card_password'];  //����
    /*
     * �ύ���
     * */
    include_once("eka/class.ekapay.php");
    $ekapay = new ekapay();
    $ekapay->type = $cardType;   //������	
    $ekapay->cardno = $card_number;   //����
    $ekapay->cardpwd = $card_password;  //����
    $ekapay->value = $amount;    //�ύ���
    $ekapay->restrict = $eka_restrict;  //��������, 0��ʾȫ��Χ
    $ekapay->orderid = $order_id;   //������
    $ekapay->callbackurl = $eka_callback_url; //����url��ַ
    $ekapay->parter = $eka_merchant_id;  //�̼�Id
    $ekapay->key = $eka_merchant_key; //�̼���Կ
    //����
    $result = $ekapay->send();

    /*
     * ������
     * */
    switch ($result) {
        case '0':
            header("location: pay_card_finish.php?order_id=$order_id");
            break;
        case '-1':
            header("location: pay_card_finish.php?order_id=$order_id");
            break;
        case '-2':
            print('ǩ�����');
            break;
        case '-3':
            print('<script language="javascript">alert("�Բ�������д�Ŀ��ſ�������"); history.go(-1);</script>');
            break;
        case '-999':
            print('<script language="javascript">alert("�Բ��𣬼�Ѷ�ӿ�ά���У���ѡ������ĳ�ֵ��ʽ��"); history.go(-1);</script>');
            break;
        default:
            print('δ֪�ķ���ֵ, ����ϵ��Ѷ��ٷ���');
            break;
    }
} else if ('card_muti' == $payType) {
    include_once("eka/class.ekapay.muti.php");

    $cardType_muti = $_POST['cardType_muti'];

    $card_number = $_POST['card_number'];
    $card_password = $_POST['card_password'];
    $card_value = $_POST['card_value'];
    $restrict = $_POST['restrict'];
    $attach = $_POST['attach'];

    $ekapay = new ekapay();

    $ekapay->type = $cardType_muti;
    $ekapay->parter = $eka_merchant_id;
    $ekapay->cardno = implode(",", $card_number);
    $ekapay->cardpwd = implode(",", $card_password);
    $ekapay->value = implode(",", $card_value);
    $ekapay->restrict = implode(",", $restrict);
    $ekapay->orderid = $order_id;
    $ekapay->attach = $attach;
    $ekapay->callbackurl = $eka_callback_url_muti;
    $ekapay->key = $eka_merchant_key;

    $result = $ekapay->send();

    switch ($result) {
        case '0':
            header("location: pay_card_finish.php?order_id=$order_id");
            break;
        case '-1':
            print("���������Ч");
            break;
        case '-2':
            print('ǩ�����');
            break;
        case '-3':
            print('<script language="javascript">alert("����Ϊ�ظ��ύ����Ѷϵͳ����������Ҳ������������̡�"); history.go(-1);</script>');
            break;
        case '-4':
            print("���ܲ���ϼ�Ѷ����Ŀ���������ֵ���򣬼�Ѷϵͳ����������Ҳ������������̡�");
            break;
        case '-999':
            print('<script language="javascript">alert("�Բ��𣬼�Ѷ�ӿ�ά���У���ѡ������ĳ�ֵ��ʽ��"); history.go(-1);</script>');
            break;
        default:
            print('δ֪�ķ���ֵ, ����ϵ��Ѷ��ٷ���');
            break;
    }
}
?>